package com.zf.shuashua.bean.advert;

import com.zf.shuashua.advert.AdvertConstants;
import com.zf.shuashua.advert.ReportConstants;
import com.zf.shuashua.api.Store;

import java.io.Serializable;
import java.util.List;

/**
 * 激励视频广告配置
 */
public class RewardConfigBean implements Serializable {

    //会员签到
    private List<AdvertConfigBean> sign;
    //自动播放
    private List<AdvertConfigBean> auto_play;
    //限次奖励
    private List<AdvertConfigBean> limit_reword;
    //首次观看
    private List<AdvertConfigBean> first;
    //分享任务
    private List<AdvertConfigBean> share;
    //点赞视频
    private List<AdvertConfigBean> like;
    //绑定微信
    private List<AdvertConfigBean> bind_wechat;
    //开启推送
    private List<AdvertConfigBean> push;
    //限时登录
    private List<AdvertConfigBean> limit_login;
    //首页宝箱
    private List<AdvertConfigBean> chest;
    //长豆评价
    private List<AdvertConfigBean> comment;

    private int indexSign = -1;
    private int indexAuto = -1;
    private int indexLimit = -1;
    private int indexFirst = -1;
    private int indexShare = -1;
    private int indexLike = -1;
    private int indexBind = -1;
    private int indexPush = -1;
    private int indexLogin = -1;
    private int indexChest = -1;
    private int indexComment = -1;

    /**
     * 轮动获取各个广告位对应的广告配置
     * @param advertType
     * @return
     */
    public AdvertConfigBean getConfigByType(String advertType){
        List<AdvertConfigBean> config = getConfigBean(advertType);
        if(config == null || config.size() < 1){
            return null;
        }
        if(config.size() == 1){
            return config.get(0);
        }
        int index = getIndexByType(advertType);
        return config.get(index);
    }

    private int getIndexByType(String advertType){
        int index = 0;
        switch (advertType) {
            case AdvertConstants.REWARD_TYPE_PUNCH:
                index = indexSign + 1 < sign.size() ? indexSign + 1 : 0;
                indexSign = index;
                break;
            case AdvertConstants.REWARD_TYPE_TASK:
                index = indexLimit + 1 < limit_reword.size() ? indexLimit + 1 : 0;
                indexLimit = index;
                break;
            case AdvertConstants.REWARD_TYPE_APPRAISE:
            case AdvertConstants.REWARD_TYPE_AUTO:
                index = indexAuto + 1 < auto_play.size() ? indexAuto + 1 : 0;
                indexAuto = index;
                break;
            case AdvertConstants.REWARD_TYPE_SHARE:
                index = indexShare + 1 < share.size() ? indexShare + 1 : 0;
                indexShare = index;
                break;
            case AdvertConstants.REWARD_TYPE_FIRST:
                index = indexFirst + 1 < first.size() ? indexFirst + 1 : 0;
                indexFirst = index;
                break;
            case AdvertConstants.REWARD_TYPE_LIKE:
                index = indexLike + 1 < like.size() ? indexLike + 1 : 0;
                indexLike = index;
                break;
            case AdvertConstants.REWARD_TYPE_BIND:
            case AdvertConstants.REWARD_TYPE_BIND_QQ:
            case AdvertConstants.REWARD_TYPE_BIND_WEIBO:
                index = indexBind + 1 < bind_wechat.size() ? indexBind + 1 : 0;
                indexBind = index;
                break;
            case AdvertConstants.REWARD_TYPE_NOTIFICATION:
                index = indexPush + 1 < push.size() ? indexPush + 1 : 0;
                indexPush = index;
                break;
            case AdvertConstants.REWARD_TYPE_NEW_WITHDRAW:
            case AdvertConstants.REWARD_TYPE_GAME:
            case AdvertConstants.REWARD_TYPE_TIME_LIMIT:
                index = indexLogin + 1 < limit_login.size() ? indexLogin + 1 : 0;
                indexLogin = index;
                break;
            case AdvertConstants.REWARD_TYPE_BUBBLE:
                index = indexChest + 1 < chest.size() ? indexChest + 1 : 0;
                indexChest = index;
                Store.getInstance().setButtleIndex(index);
                break;
//            case AdvertConstants.REWARD_TYPE_DWJ:
//            case AdvertConstants.REWARD_TYPE_POOL:
//            case AdvertConstants.REWARD_TYPE_TURNTABLE:
//            case AdvertConstants.REWARD_TYPE_QIXI:
//                index = indexComment + 1 < comment.size() ? indexComment + 1 : 0;
//                indexComment = index;
//                break;
            default:
                index = indexComment + 1 < comment.size() ? indexComment + 1 : 0;
                indexComment = index;
                break;
        }
        return index;
    }

    private List<AdvertConfigBean> getConfigBean(String advertType) {
        List<AdvertConfigBean> configBean = null;
        switch (advertType) {
            case AdvertConstants.REWARD_TYPE_PUNCH:
                configBean = sign;
                break;
            case AdvertConstants.REWARD_TYPE_TASK:
                configBean = limit_reword;
                break;
            case AdvertConstants.REWARD_TYPE_APPRAISE:
            case AdvertConstants.REWARD_TYPE_AUTO:
                configBean = auto_play;
                break;
            case AdvertConstants.REWARD_TYPE_SHARE:
                configBean = share;
                break;
            case AdvertConstants.REWARD_TYPE_FIRST:
                configBean = first;
                break;
            case AdvertConstants.REWARD_TYPE_LIKE:
                configBean = like;
                break;
            case AdvertConstants.REWARD_TYPE_BIND:
            case AdvertConstants.REWARD_TYPE_BIND_QQ:
            case AdvertConstants.REWARD_TYPE_BIND_WEIBO:
                configBean = bind_wechat;
                break;
            case AdvertConstants.REWARD_TYPE_NOTIFICATION:
                configBean = push;
                break;
            case AdvertConstants.REWARD_TYPE_NEW_WITHDRAW:
            case AdvertConstants.REWARD_TYPE_GAME:
            case AdvertConstants.REWARD_TYPE_TIME_LIMIT:
                configBean = limit_login;
                break;
            case AdvertConstants.REWARD_TYPE_BUBBLE:
                configBean = chest;
                break;
//            case AdvertConstants.REWARD_TYPE_DWJ:
//            case AdvertConstants.REWARD_TYPE_POOL:
//            case AdvertConstants.REWARD_TYPE_TURNTABLE:
//            case AdvertConstants.REWARD_TYPE_QIXI:
//                configBean = comment;
//                break;
            default:
                configBean = comment;
                break;
        }
        return configBean;
    }


    public List<AdvertConfigBean> getSign() {
        return sign;
    }

    public void setSign(List<AdvertConfigBean> sign) {
        this.sign = sign;
    }

    public List<AdvertConfigBean> getAuto_play() {
        return auto_play;
    }

    public void setAuto_play(List<AdvertConfigBean> auto_play) {
        this.auto_play = auto_play;
    }

    public List<AdvertConfigBean> getLimit_reword() {
        return limit_reword;
    }

    public void setLimit_reword(List<AdvertConfigBean> limit_reword) {
        this.limit_reword = limit_reword;
    }

    public List<AdvertConfigBean> getFirst() {
        return first;
    }

    public void setFirst(List<AdvertConfigBean> first) {
        this.first = first;
    }

    public List<AdvertConfigBean> getShare() {
        return share;
    }

    public void setShare(List<AdvertConfigBean> share) {
        this.share = share;
    }

    public List<AdvertConfigBean> getLike() {
        return like;
    }

    public void setLike(List<AdvertConfigBean> like) {
        this.like = like;
    }

    public List<AdvertConfigBean> getBind_wechat() {
        return bind_wechat;
    }

    public void setBind_wechat(List<AdvertConfigBean> bind_wechat) {
        this.bind_wechat = bind_wechat;
    }

    public List<AdvertConfigBean> getPush() {
        return push;
    }

    public void setPush(List<AdvertConfigBean> push) {
        this.push = push;
    }

    public List<AdvertConfigBean> getLimit_login() {
        return limit_login;
    }

    public void setLimit_login(List<AdvertConfigBean> limit_login) {
        this.limit_login = limit_login;
    }

    public List<AdvertConfigBean> getChest() {
        return chest;
    }

    public void setChest(List<AdvertConfigBean> chest) {
        this.chest = chest;
    }

    public List<AdvertConfigBean> getComment() {
        return comment;
    }

    public void setComment(List<AdvertConfigBean> comment) {
        this.comment = comment;
    }

    public int getIndexChest() {
        return indexChest;
    }

    public void setIndexChest(int indexChest) {
        this.indexChest = indexChest;
    }
}
